package com.bl.student.dao.repository;

import com.bl.student.dao.model.CommentEntity;
import com.bl.student.dao.model.UserEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by yujingyi on 2018/2/1.
 */
public interface CommentRepository extends PagingAndSortingRepository<CommentEntity, String> {

    Page<CommentEntity> findByCreatorIdOrderByCreateTimeDesc(String creatorId, Pageable pageable);

    Page<CommentEntity> findByReceiverIdOrderByCreateTimeDesc(String receiverId, Pageable pageable);

    List<CommentEntity> findByReceiverIdOrderByCreateTimeDesc(String receiverId);

    List<CommentEntity> findByTaskId(String taskId);

    @Query(value = "select * from COMMENT where if(?1 !='',creator_id=?1,1=1) and if(?2 !='',receiver_id=?2,1=1)" +
            "and if(?3 !='',COMMENT.type =?3,1=1) and if(?4 !='',task_id=?4,1=1) ORDER BY create_time DESC \n#pageable\n",
            countQuery ="select * from COMMENT where if(?1 !='',creator_id=?1,1=1) and if(?2 !='',receiver_id=?2,1=1) and if(?3 !='',COMMENT.type=?3,1=1) and if(?4 !='',task_id=?4,1=1)",
            nativeQuery = true)
    Page <CommentEntity>  findMultList(String creatorId,String receiverId,String type,String taskId, Pageable pageable);

}
